Skip to content

Fix for having two or more links in normative text#137

Merged
james-ball-qualcomm merged 1 commit intomainfrom
136-adoc-link-replacement-to-html-bug
Nov 27, 2025
Merged

Fix for having two or more links in normative text#137
james-ball-qualcomm merged 1 commit intomainfrom
136-adoc-link-replacement-to-html-bug

Conversation

@james-ball-qualcomm
Copy link
Collaborator

No description provided.

Signed-off-by: James Ball <jameball@qti.qualcomm.com>
@james-ball-qualcomm james-ball-qualcomm merged commit 19d71fa into main Nov 27, 2025
2 checks passed
@james-ball-qualcomm james-ball-qualcomm deleted the 136-adoc-link-replacement-to-html-bug branch November 27, 2025 16:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug in the normative rules generation where having two or more links in the same normative text would be incorrectly processed. The previous implementation used greedy regex patterns that would match from the first << to the last >>, treating everything in between as a single link. The fix changes to a non-greedy pattern and consolidates the link parsing logic.

Key Changes:

  • Replaced two separate regex patterns (for links with and without custom text) with a single non-greedy pattern
  • Implemented comma-splitting logic to distinguish between simple links and links with custom text
  • Added test cases for multiple links in the same normative text (both with and without custom text)

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/create_normative_rules.rb Refactored link parsing to use non-greedy regex and consolidated the two separate gsub calls into one with comma-based parsing
tests/norm-rule/test.yaml Added hyperlink5 and hyperlink6 test definitions
tests/norm-rule/test.adoc Added test cases with multiple links in the same normative text
tests/norm-rule/expected/test-norm-tags.json Updated expected JSON output with new test cases
tests/norm-rule/expected/test-norm-rules.xlsx Updated expected Excel output (binary file)
tests/norm-rule/expected/test-norm-rules.json Updated expected JSON rules output with new test cases
tests/norm-rule/expected/test-norm-rules.html Updated expected HTML output showing properly parsed multiple links
tests/norm-rule/expected/test-norm-rules.adoc Updated expected AsciiDoc output with new test cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

elsif split_texts.length == 2
tag2html_link(split_texts[0], split_texts[1], html_fname)
else
fail("Hyperlink '$1' contains too many commas")
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message uses single quotes, which prevents Ruby from interpolating $1. The message will literally display "$1" instead of the actual hyperlink content. Change to double quotes: "Hyperlink \"#{$1}\" contains too many commas" or use "Hyperlink '#{$1}' contains too many commas" for proper interpolation.

Suggested change
fail("Hyperlink '$1' contains too many commas")
fail("Hyperlink '#{$1}' contains too many commas")

Copilot uses AI. Check for mistakes.
# will return multiple <<link>> in the same text as one.
tag_text.gsub!(/#{LT_UNICODE_STR}#{LT_UNICODE_STR}(.+?)#{GT_UNICODE_STR}#{GT_UNICODE_STR}/) do
# Look to see if custom text has been provided.
split_texts = $1.split(",")
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider trimming whitespace from split_texts elements before passing them to tag2html_link. Currently, <<link , custom text>> (with space before comma) would result in "link " being used as the tag reference, which could cause issues. Adding .map(&:strip) after the split would handle this: split_texts = $1.split(",").map(&:strip)

Suggested change
split_texts = $1.split(",")
split_texts = $1.split(",").map(&:strip)

Copilot uses AI. Check for mistakes.
Comment on lines +1073 to +1075
if split_texts.length == 0
fail("Hyperlink '$1' is empty")
elsif split_texts.length == 1
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition split_texts.length == 0 is impossible to reach. When splitting a non-empty string (captured by .+?), the result will always have at least one element. Consider removing this dead code or replacing it with a more meaningful check.

Suggested change
if split_texts.length == 0
fail("Hyperlink '$1' is empty")
elsif split_texts.length == 1
if split_texts.length == 1

Copilot uses AI. Check for mistakes.
split_texts = $1.split(",")

if split_texts.length == 0
fail("Hyperlink '$1' is empty")
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message uses single quotes, which prevents Ruby from interpolating $1. The message will literally display "$1" instead of the actual hyperlink content. Change to double quotes: "Hyperlink \"#{$1}\" is empty" or use "Hyperlink '#{$1}' is empty" for proper interpolation.

Suggested change
fail("Hyperlink '$1' is empty")
fail("Hyperlink '#{$1}' is empty")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adoc link replacement to HTML has bug when multiple links in same tagged text

2 participants